package com.itheim.array;

import java.util.Scanner;

/*
录入数组的数组反转
 */
public class ArrayDemo07 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //建立数组,内存超大
        int arr[] = new int[10000];
        //建立count判断数组实际内容所占数组长度的大小
        int count = 0;
        //建立死循环录入数组,录入值为-1时跳出循环
        while (true) {
            System.out.println("请输入第" + (count + 1) + "个数:(输入-1以结束输入)");
            arr[count] = sc.nextInt();
            if (arr[count] == -1) {
                break;
            }
            count++;
        }
        //循环输出录入的值
        for (int i = 0; i < count; i++) {
            System.out.println("arr[" + i + "]" + "=" + arr[i]);
        }
        System.out.println("----------");
        int arr1[] = reverse(arr, count);
        //循环输出反转后的值
        for (int i = 0; i < count; i++) {
            arr[i] = arr1[i];
            System.out.println("arr1[" + i + "]" + "=" + arr[i]);
        }
    }

    //建立数组反转的方法
    public static int[] reverse(int arr[], int count) {
        int start = 0;
        int end = count - 1;
        int temp = 0;
        for (int i = 0; i < (int) count / 2; i++) {
            temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
        return arr;
    }
}
